package com.magic233.service;

import com.magic233.entity.Admins;
import com.magic233.entity.Users;
import com.magic233.mapper.AdminsMapper;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;

/**
 * ClassName: AdminsServiceImpl
 * Description:
 * date: 2021/5/30 15:49
 * author: zouyuan
 */
@Service
public class AdminsServiceImpl implements AdminsService {
    @Autowired
    private AdminsMapper adminsMapper;

    @Autowired
    private LogsService logsService;

    @Override
    public int addAdmin(Users user, Long uid) {
        Admins a = new Admins();
        a.setId(uid);
        a.setBluenum(3);
        a.setYellownum(5);
        a.setRednum(8);
        int re = adminsMapper.insert(a);
        if (re == 1) {
            String thing = "超级管理员：{" + user.getPhone() + "--" + user.getUsername() + "}新增了管理员：" + uid;
            logsService.addLog(thing);
        }
        return re;
    }

    @Override
    public int deleteAdmin(Users user, Long uid) {
        int re = adminsMapper.deleteByPrimaryKey(uid);

        if (re == 1) {
            String thing = "超级管理员：{" + user.getPhone() + "--" + user.getUsername() + "}删除了管理员：" + uid;
            logsService.addLog(thing);
        }
        return re;
    }

    @Override
    public List<Admins> selectAdmins() {
        List<Admins> admins = adminsMapper.selectAdmins();
        return admins;
    }

    @Override
    public Admins selectWarnSet(Long id) {
        Admins admins = adminsMapper.selectByPrimaryKey(id);
        return admins;
    }

    @Override
    public int warnSet(Admins admin) {
        int re = adminsMapper.updateByPrimaryKeySelective(admin);
        if (re == 1) {
            String thing = "管理员：{" + admin.getId() + "}设置了预警天数：" + admin.getBluenum() + " " + admin.getYellownum() + " " + admin.getRednum();
            logsService.addLog(thing);
        }
        return re;
    }
}
